<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
		<style type="text/css">
			.layui-table th {
				position: relative;
				min-height: 20px;
				height: 35px;
				line-height: 20px;
				font-size: 14px;
				padding: 0px 0px;
			}

			.layui-table td {
				position: relative;
				min-height: 20px;
				height: 100%;
				line-height: 14px;
				font-size: 14px;
				padding: 0px 0px;
			}

			.layui-textarea {
				width: 302px;
				height: 40px;
			}

			.inp {
				width: 190px;
			}

			.inline-block {
				width: 310px;
				display: inline-block;
			}

			.flex {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.demo-tree-box {
				max-height: calc(100vh - 110px);
				overflow: hidden;
			}

			.demo-tree-box:hover {
				overflow-y: auto;
			}
		</style>
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<div class="layui-card">
					<div class="layui-card-body">
						<div class="layui-row layui-col-space15">
							<div class="layui-btn-sm2 layui-col-md2 layui-col-xs2">
								<div id="test10" class="demo-tree demo-tree-box" style="width: 100%;"></div>
							</div>
							<div class="layui-btn-sm10 layui-col-md10 layui-col-xs10">
								<form v-if="formShow" class="layui-form" lay-filter="test_detail1">
									<div style="height: 50vh;overflow-y: scroll;">
										<div class="layui-form-item">
											<label class="layui-form-label">活动模板:</label>
											<div class="layui-input-inline">
												<input type="text" name="activeName" disabled class="layui-input" id=""
													autocomplete="on" placeholder="请选择活动模板" />
											</div>
											<div class="layui-input-inline">
												<button type="button" class="layui-btn"
													onclick="chooseActive()">选择活动模板</button>
											</div>
										</div>
										<div class="layui-form-item">
											<label class="layui-form-label">频道编号:</label>
											<div class="layui-input-inline">
												<div id="channelidText"
													style="display: flex;align-items: center;height: 38px;">请在左侧选择频道编号
												</div>
												<input type="hidden" lay-verify="required" name="channelid" disabled
													class="layui-input" autocomplete="off" placeholder="请在左侧选择频道编号">
											</div>
											<!-- <div class="layui-input-inline">
<button type="button" class="layui-btn" onclick="chooseLimit()">选择频道</button>
</div> -->
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">活动状态:<span
													style="color:red">*</span></label>
											<div class="layui-input-block on_off">
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">客户端</label>
											<div class="layui-input-block icon_type">
											</div>
										</div>
										<br>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">活动标题：</label>
											<div class="layui-input-block">
												<input type="text" name="title" class="layui-input" id="title"
													autocomplete="off" placeholder="标题">
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">活动名称：</label>
											<div class="layui-input-block">
												<input type="text" name="name" class="layui-input" id="name"
													autocomplete="off" placeholder="名称">
											</div>
										</div>
										<br>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label" style="width:5.9375rem;">是否首页显示</label>
											<div class="layui-input-inline">
												<input type="radio" name="is_recommend" value="0" title="否" checked
													disabled>
												<input type="radio" name="is_recommend" value="1" title="是" disabled>
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">首页倒计时</label>
											<div class="layui-input-inline">
												<input type="radio" name="istimer" value="1" title="显示" checked
													disabled>
												<input type="radio" name="istimer" value="0" title="不显示" disabled>
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label" style="width:5.9375rem;">商品排列方式</label>
											<div class="layui-input-inline">
												<input type="radio" name="sorted" value="0" title="竖排" checked disabled>
												<input type="radio" name="sorted" value="1" title="横排" disabled>
											</div>
										</div>
										<br>
										<div class="layui-form-item">
											<div class="layui-inline">
												<label class="layui-form-label">活动类型：
												</label>
												<div class="layui-input-inline">
													<select name="type" class="seckill_type">
													</select>
												</div>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">专属等级：</label>
												<div class="layui-input-inline">
													<select name="grade" class="site_union">
													</select>
												</div>
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">图标<span style="color:red">*</span></label>
											<div class="layui-input-block">
												<button type="button" class="layui-btn layui-btn-normal"
													onclick="choose(1)">上传图标</button><span style="color:red">
													<p>建议上传340*220大小图片</p>
												</span>
												<ul class="show_img_ul" id="icon_url"></ul>
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">主图<span style="color:red">*</span></label>
											<div class="layui-input-block">
												<button type="button" class="layui-btn layui-btn-normal"
													onclick="choose(2)">上传图片</button><span style="color:red">
													<p>建议上传750*375大小图片</p>
												</span>
												<ul class="show_img_ul" id="img_url"></ul>
											</div>
										</div>
										<br>
										<div class="layui-form-item">
											<div style="display: inline-block;">
												<label class="layui-form-label">开始日期：</label>
												<div class="layui-input-inline">
													<input type="text" name="dates" class="layui-input" id="dates"
														autocomplete="off" placeholder="开始日期：">
												</div>
											</div>
											<div style="display: inline-block;">
												<label class="layui-form-label">开始时间：</label>
												<div class="layui-input-inline">
													<input type="text" name="times" class="layui-input" id="times"
														autocomplete="off" placeholder="开始时间：">
												</div>
											</div>
											<div style="display: inline-block;">
												<label class="layui-form-label">结束时间：</label>
												<div class="layui-input-inline">
													<input type="text" name="endtime" class="layui-input" id="endtime"
														autocomplete="off" placeholder="结束时间：">
												</div>
											</div>
										</div>
										<div class="layui-form-item">
											<div class="inline-block">
												<label class="layui-form-label">列表链接：</label>
												<div class="layui-input-block">
													<input type="text" name="url" class="layui-input inp" id="url"
														autocomplete="off" placeholder="列表链接">
												</div>
											</div>
											<div class="inline-block">
												<label class="layui-form-label">详情链接：</label>
												<div class="layui-input-block">
													<input type="text" name="url_detail" class="layui-input inp"
														id="url_detail" autocomplete="off" placeholder="详情链接">
												</div>
											</div>
											<div class="inline-block">
												<label class="layui-form-label">排序：</label>
												<div class="layui-input-block">
													<input type="text" name="oid" class="layui-input inp" id="oid"
														autocomplete="off" placeholder="排序">
												</div>
											</div>
										</div>
										<div class="layui-form-item inline-block">
											<div class="inline-block" style="width: 380px;">
												<label class="layui-form-label">活动主题色<span
														style="color:red">*</span></label>
												<div class="layui-input-inline">
													<input type="text" value="" placeholder="活动主题色"
														class="layui-input inp" id="color" lay-verify="required"
														name='color' />
												</div>
												<div class="layui-inline" style="left: -11px;">
													<div id="test-form"></div>
												</div>
											</div>
										</div>
										<div class="layui-form-item inline-block">
											<div style="width: 460px;">
												<label class="layui-form-label" style="width: 130px;">单人购买上限：</label>
												<div class="layui-input-block">
													<input type="text" name="top_count" class="layui-input inp"
														id="top_count" autocomplete="off" placeholder="单人购买上限">
												</div>
											</div>
										</div>
										<br>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">活动内容：</label>
											<div class="layui-input-block">
												<textarea class="layui-textarea" name="content" lay-verify="content"
													id=""></textarea>
											</div>
										</div>
										<div class="layui-form-item" style="display: inline-block;">
											<label class="layui-form-label">备注：</label>
											<div class="layui-input-block">
												<textarea type="text" id="notes" name="notes" autocomplete="off"
													placeholder="备注" class="layui-textarea" /></textarea>
											</div>
										</div>
									</div>
									<!-- 商品表单区域 拼一把 -->
									<div v-if="activeName !== ''" class="layui-form-item"
										style="padding-top: 20px;border-top: 1px solid #000;height: 30vh;overflow-y: scroll;">
										<div class="layui-input-inline"
											style="display: inline-block;margin-bottom: 20px;padding-left: 50px;">
											<span>添加商品</span>
											<button type="button" class="layui-btn" onclick="choosedata()">添加商品</button>
										</div>
										<div v-if="activeName === '拼一把'"
											style="display: inline-block;margin-bottom: 20px;">
											<span>选择佣金模板</span>
											<el-select v-model="temp" placeholder="请选择佣金模板" @change="tempChange">
												<el-option v-for="item in tempList" :key="item.id" :label="item.name"
													:value="item.id">
												</el-option>
											</el-select>
											<button type="button" class="layui-btn" @click="recalculate">重新计算</button>
										</div>
										<table class="layui-table" id="testtable">
											<colgroup>
												<col>
												<col>
												<col>
												<col>
												<col>
											</colgroup>
											<thead>
												<tr v-if="activeName === '拼一把'">
													<th></th>
													<th v-for="(item, index) in pybTh" :key="index"
														:style="{ width: item.width + 'px' }">
														{{ item.name }}
													</th>
												</tr>
												<tr v-if="activeName !== '拼一把' && activeName !== ''">
													<th style="width: 40px;"></th>
													<th v-for="(item, index) in todayTh" :key="index"
														:style="{ width: item.width + 'px' }">
														{{ item.name }}
													</th>
												</tr>
											</thead>
											<tbody>
												<tr v-for="(item, index) in productList" :key="item.id">
													<td v-if="activeName !== ''">{{ index+1 }}</td>
													<!-- 商品编号 -->
													<td v-if="activeName !== ''">{{ item.skuid }}</td>
													<!-- 商品名称 -->
													<td v-if="activeName !== ''">{{ item.skuname }}</td>
													<!-- 会员价 -->
													<td v-if="activeName !== ''">{{ item.price_member }}</td>
													<!-- 原抵扣积分 -->
													<td v-if="activeName !== '拼一把' && activeName !== ''">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text"></div>
													</td>
													<!-- 秒杀价 -->
													<td v-if="activeName !== '拼一把' && activeName !== ''">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text"></div>
													</td>
													<!-- 积分使用 -->
													<td v-if="activeName !== '拼一把' && activeName !== ''">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text"></div>
													</td>
													<!-- 抢购数量 -->
													<td v-if="activeName !== '拼一把' && activeName !== ''">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text"></div>
													</td>
													<!-- 已抢购数量 -->
													<td v-if="activeName !== '拼一把' && activeName !== ''">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text"></div>
													</td>
													<!-- 团购价 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" @blur="comTemp" type="text"
																name="price" :value="item.price"></div>
													</td>
													<!-- 补贴 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="subsidy"
																:value="item.subsidy" /></div>
													</td>
													<!-- 团人数 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" @change="group_numChange"
																type="text" name="group_num" :value="item.group_num">
														</div>
													</td>
													<!-- 中奖人数 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="group_wnum"
																:value="item.group_wnum"></div>
													</td>
													<!-- 显示已参团人数 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="group_onum"
																:value="item.group_onum"></div>
													</td>
													<!-- 活动数量 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="stock"
																:value="item.stock"></div>
													</td>
													<!-- 显示已购数量 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="sales"
																:value="item.sales"></div>
													</td>
													<!-- 购买上限 -->
													<td>
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="top_count"
																:value="item.top_count"></div>
													</td>
													<!-- 显示数量 -->
													<td>
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="num"
																:value="item.num"></div>
													</td>
													<!-- 团时长 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" lay-verify="required" type="text"
																name="duration" :value="item.duration"></div>
													</td>
													<!-- 发起佣金 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="launch_fee"
																:value="item.launch_fee"></div>
													</td>
													<!-- 直推佣金 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="direct_fee"
																:value="item.direct_fee"></div>
													</td>
													<!-- 间推佣金 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="indirect_fee"
																:value="item.indirect_fee"></div>
													</td>
													<!-- 团长佣金 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="leader_fee"
																:value="item.leader_fee"></div>
													</td>
													<!-- 管理奖 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="team_fee"
																:value="item.team_fee"></div>
													</td>
													<!-- 合伙人佣金 -->
													<td v-if="activeName === '拼一把'">
														<div class="flex"><input class="layui-input"
																lay-verify="required" type="text" name="copartner_fee"
																:value="item.copartner_fee"></div>
													</td>
													<!-- 排序 -->
													<td>{{ index+1 }}</td>
												</tr>
											</tbody>
										</table>
									</div>
									<div class="layui-form-item layui-layout-admin">
										<div class="layui-input-block">
											<div class="layui-footer" style="left: 0;">
												<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
												<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
											</div>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script>
			document.write('<script src="//' + (location.host || 'localhost').split(':')[0] +
				':35929/livereload.js?snipver=1"></' + 'script>')
		</script>
		<script>
			document.addEventListener('LiveReloadDisconnect', function() {
				setTimeout(function() {
					window.location.reload();
				}, 500);
			})
		</script>
	</body>
	<script src="../../../../layuiadmin/layui/layui.js"></script>
	<script src="../../../../js/jquery.min.js"></script>
	<script src="../../../../js/jquery.jqprint-0.3.js"></script>
	<script src="../../../../js/common.js"></script>
	<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
	<script src="https://unpkg.com/element-ui/lib/index.js"></script>
	<script>
		var app = new Vue({
			el: '.layui-fluid',
			data() {
				return {
					formShow: true,
					activeName: '',
					pybTh: [{
							name: '商品编号',
							width: 100
						},
						{
							name: '商品名',
							width: 250
						},
						{
							name: '会员价',
							width: 70
						},
						{
							name: '团购价',
							width: 70
						},
						{
							name: '补贴',
							width: 70
						},
						{
							name: '团人数',
							width: 70
						},
						{
							name: '中奖人数',
							width: 70
						},
						{
							name: '显示已参团人数',
							width: 120
						},
						{
							name: '活动数量',
							width: 70
						},
						{
							name: '显示已购数量',
							width: 120
						},
						{
							name: '购买上限',
							width: 70
						},
						{
							name: '显示数量',
							width: 70
						},
						{
							name: '团时长',
							width: 60
						},
						{
							name: '发起佣金',
							width: 90
						},
						{
							name: '直推佣金',
							width: 90
						},
						{
							name: '间推佣金',
							width: 90
						},
						{
							name: '团长佣金',
							width: 90
						},
						{
							name: '管理奖',
							width: 90
						},
						{
							name: '合伙人佣金',
							width: 100
						},
						{
							name: '排序',
							width: 40
						}
					],
					productList: [],
					todayTh: [{
							name: '商品编号',
							width: 100
						},
						{
							name: '商品名',
							width: 250
						},
						{
							name: '会员价',
							width: 70
						},
						{
							name: '原抵扣积分',
							width: 70
						},
						{
							name: '秒杀价',
							width: 70
						},
						{
							name: '积分使用',
							width: 70
						},
						{
							name: '抢购数量',
							width: 70
						},
						{
							name: '已抢购数量',
							width: 70
						},
						{
							name: '购买上限',
							width: 70
						},
						{
							name: '显示数量',
							width: 70
						},
						{
							name: '排序',
							width: 40
						}
					],
					tempList: [],
					temp: '',
					tempObj: {},
					type: 0
				}
			},
			beforeMount() {},
			methods: {
				tempChange(e) {
					this.tempList.forEach(item => {
						if (item.id === e) {
							this.tempObj = item
						}
					})
					// window.tempObjF()
				},
				recalculate() {
					let that = this
					let tempObj = JSON.parse(JSON.stringify(this.tempObj))
					if (tempObj.name) {
						let testtable = document.getElementById('testtable');
						let rows = testtable.rows;
						let list = []
						for (let i = 0; i < rows.length; i++) {
							let cells = rows[i].cells
							list.push($(cells))
						}
						delete list[0]
						let array = list
						console.log(array, '----')
						if (array.length <= 1) {
							layer.msg('请先添加商品')
						} else {
							layer.confirm('确定要重新计算', function() {
								layer.closeAll()
								for (let i = 0; i < array.length; i++) {
									if (array[i] !== undefined) {
										let price = array[i].find('input[name=price]').val()
										if (!price) {
											let skuid = array[i].find('input[name=skuid]').val()
											layer.msg(`请输入商品编号为${skuid}的团购价,重新点击按钮`)
										} else {
											let group_num = array[i].find('input[name=group_num]').val()
											if (!group_num) {
												// 没有输入团人数
												that.recal(array[i])
											} else {
												// 输入了团人数
												this.reacl2(array[i])
											}
										}
									}
								}
							})
						}
					} else {
						layer.msg('请先选择模板')
					}
				},
				// 重新计算 没有输入团人数
				recal(obj) {
					let tempObj = JSON.parse(JSON.stringify(this.tempObj))
					let price = $(obj).find("input[name=price]").val()
					price = parseInt(price)
					$(obj).find("input[name=launch_fee]").val(this.getBili(tempObj.launch_fee, price))
					$(obj).find("input[name=leader_fee]").val(this.getBili(tempObj.leader_fee, price))
					$(obj).find("input[name=team_fee]").val(this.getBili(tempObj.team_fee, price))
					$(obj).find("input[name=indirect_fee]").val(this.getBili(tempObj.indirect_fee, price))
					$(obj).find("input[name=direct_fee]").val(this.getBili(tempObj.direct_fee, price))
					$(obj).find("input[name=copartner_fee]").val(this.getBili(tempObj.copartner_fee, price))
				},
				// 重新计算 输入了团人数
				reacl2(obj) {
					let tempObj = JSON.parse(JSON.stringify(this.tempObj))
					let price = $(obj).find("input[name=price]").val()
					let group_num = $(obj).find("input[name=group_num]").val()
					$(obj).find("input[name=launch_fee]").val(this.getT(this.getBili(tempObj.launch_fee, price),
						group_num))
					$(obj).find("input[name=leader_fee]").val(this.getT(this.getBili(tempObj.leader_fee, price),
						group_num))
					$(obj).find("input[name=team_fee]").val(this.getT(this.getBili(tempObj.team_fee, price),
						group_num))
					$(obj).find("input[name=indirect_fee]").val(this.getT(this.getBili(tempObj.indirect_fee, price),
						group_num))
					$(obj).find("input[name=direct_fee]").val(this.getT(this.getBili(tempObj.direct_fee, price),
						group_num))
					$(obj).find("input[name=copartner_fee]").val(this.getT(this.getBili(tempObj.copartner_fee, price),
						group_num))
				},
				comTemp(e) {
					let tr = e.currentTarget.parentElement.parentElement.parentElement
					let price = $(tr).find('input[name=price]').val()
					let tempObj = JSON.parse(JSON.stringify(this.tempObj))
					if (tempObj.launch_fee) {
						$(tr).find('input[name=launch_fee]').val(this.getBili(tempObj.launch_fee, price))
						$(tr).find('input[name=leader_fee]').val(this.getBili(tempObj.leader_fee, price))
						$(tr).find('input[name=team_fee]').val(this.getBili(tempObj.team_fee, price))
						$(tr).find('input[name=indirect_fee]').val(this.getBili(tempObj.indirect_fee, price))
						$(tr).find('input[name=direct_fee]').val(this.getBili(tempObj.direct_fee, price))
						$(tr).find('input[name=copartner_fee]').val(this.getBili(tempObj.copartner_fee, price))
					}
				},
				getBili(num1, num2) {
					let num = Math.round(num1 * num2) / 100
					return num.toFixed(2)
				},
				getT(num1, num2) {
					let num = num1 / num2
					return num.toFixed(2)
				},
				group_numChange(e) {
					let tr = e.currentTarget.parentElement.parentElement.parentElement
					let tempObj = JSON.parse(JSON.stringify(this.tempObj))
					let price = $(tr).find('input[name=price]').val()
					let group_num = $(tr).find("input[name=group_num]").val()
					if (price) {
						if (tempObj.launch_fee && group_num) {
							$(tr).find("input[name=launch_fee]").val(this.getT(this.getBili(tempObj.launch_fee,
								price), group_num))
							$(tr).find("input[name=leader_fee]").val(this.getT(this.getBili(tempObj.leader_fee,
								price), group_num))
							$(tr).find("input[name=team_fee]").val(this.getT(this.getBili(tempObj.team_fee, price),
								group_num))
							$(tr).find("input[name=indirect_fee]").val(this.getT(this.getBili(tempObj.indirect_fee,
								price), group_num))
							$(tr).find("input[name=direct_fee]").val(this.getT(this.getBili(tempObj.direct_fee,
								price), group_num))
							$(tr).find("input[name=copartner_fee]").val(this.getT(this.getBili(tempObj.copartner_fee,
								price), group_num))
						} else if (!group_num) {
							$(tr).find('input[name=launch_fee]').val(this.getBili(tempObj.launch_fee, price))
							$(tr).find('input[name=leader_fee]').val(this.getBili(tempObj.leader_fee, price))
							$(tr).find('input[name=team_fee]').val(this.getBili(tempObj.team_fee, price))
							$(tr).find('input[name=indirect_fee]').val(this.getBili(tempObj.indirect_fee, price))
							$(tr).find('input[name=direct_fee]').val(this.getBili(tempObj.direct_fee, price))
							$(tr).find('input[name=copartner_fee]').val(this.getBili(tempObj.copartner_fee, price))
						}
					} else {
						layer.msg('请先输入团购价')
					}
				}
			}
		})
		var _data = {
			channelid: ''
		}
		var _member = {}
		var _data1 = {}
		var tempObj = {}
		layui.config({
			base: '../../../../layuiadmin/'
		}).extend({
			index: 'lib/index' //主入口模块
		}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker', 'table', 'tree'], function() {
			var $ = layui.$,
				admin = layui.admin,
				upload = layui.upload,
				laytpl = layui.laytpl,
				laydate = layui.laydate,
				layedit = layui.layedit,
				colorpicker = layui.colorpicker,
				form = layui.form,
				table = layui.table,
				tree = layui.tree;
			var img_arr1 = [],
				img_arr2 = [];
			on_off_show('radio')
			// seckill_type_show_shop("option")
			site_union_show("option")
			icon_type_show_shop('checkbox')
			form.on('submit(demo1)', function(data) {
				var data = data.field;
				if (img_arr2.length !== 0 && img_arr1.length !== 0) {
					_data.icon_url = img_arr1.join(',');
					_data.img_url = img_arr2.join(',');
					_data = Object.assign(_data, data);
					_data.client = ''
					for (item in data) {
						if (/^c/.test(item)) {
							if (item.substr(0, 6) == 'client') {
								_data.client += data[item] + ','
								console.log(item)
								console.log(data[item])
							}
						}
					}
					_data.client = (_data.client.substring(_data.client.length - 1) == ',') ? _data.client
						.substring(0, _data.client.length - 1) : _data.client;
					let goods_data = []
					if (app.productList.length !== 0) {
						goods_data = app.productList
						_data.goods_data = JSON.stringify(goods_data)
						layer.confirm('确认要提交数据?', function() {
							loading()
							submit(server.shop_promotion_insert)
						}, function() {
							layer.msg('取消操作')
						})
					} else {
						layer.msg('活动商品不允许空')
					}
				} else {
					layer.msg('请上传图片')
				}
				return false
			})

			function submit(url) {
				console.log(url)
				$.post(url, _data, function(res, status) {
					if (status === 'success') {
						if (res.code === 0) {
							layer.alert('操作成功', function() {
								parent.layer.closeAll();
								parent.layui.table.reload('test-table-operate');
							});
						} else {
							layer.closeAll('loading')
							layer.msg(res.msg);
						}
					} else {
						closeloading();
						layer.msg('服务器连接错误')
					}
				})
			}
			var leftData1 = {
				page: 1,
				limit: 10,
				filterRules: [],
				sort: [],
				fid: '',
			};
			getLeftData()
			// 获取左侧分类
			function getLeftData() {
				$.get(server.queryshopmodulelist, leftData1, function(res, status) {
					if (status == 'success') {
						if (res.code === 0) {
							// console.log(app.formShow)
							loading()
							var data = res.module_list.data
							const treeData = fnSetTreeData1(data)
							treeData.shift()
							treeData[0].spread = true;
							if (treeData[0].children) {
								treeData[0].children[0].spread = true;
							}
							tree.render({
								elem: '#test10',
								data: treeData,
								onlyIconControl: true,
								accordion: true,
								click: (e) => {
									console.log(e.elem[0])
									_data.channelid = e.data.id
									let channelidText = document.getElementById('channelidText')
									channelidText.innerHTML = e.data.name
									$('input[name=channelid]').val(e.data.id)
									var nodes = document.getElementsByClassName("layui-tree-txt");
									for (var i = 0; i < nodes.length; i++) {
										if (nodes[i].innerHTML === e.data.name)
											nodes[i].style.color = "red";
										else
											nodes[i].style.color = "#555";
									}
								}
							});
							closeloading()
							// setTimeout(()=>{
							// app.formShow = true
							// },500)
						}
					}
				})
			}

			function fnSetTreeData1(data) {
				var data = [...data];
				var tree = data.filter((father) => {
					var branchArr = data.filter((child) => {
						const a = child.sid.split(',')
						if (a.length < 3) {
							if (father.id == child.sid.split(',')[1]) child._hasParent = true;
							return father.id == child.sid.split(',')[1];
						} else {
							if (father.id == child.sid.split(',')[2]) child._hasParent = true;
							return father.id == child.sid.split(',')[2];
						}
					});
					if (branchArr.length > 0) father.children = branchArr;
					return !father._hasParent;
				});
				tree = tree.filter((item) => {
					return !item._hasParent;
				})
				return tree
			}
			//日期时间选择器
			laydate.render({
				elem: '#dates',
				type: 'date'
			});
			//日期时间选择器
			laydate.render({
				elem: '#times',
				type: 'time'
			});
			//日期时间选择器
			laydate.render({
				elem: '#endtime',
				type: 'datetime'
			});
			//表单赋值
			colorpicker.render({
				elem: '#test-form',
				done: function(color) {
					$('#color').val(color);
				}
			});
			// 佣金计算
			window.tempObjF = function() {
				tempObj = app.tempObj
			}
			getTempData()

			function getTempData() {
				let that = app
				$.post(server.shop_feetemp_list, function(res, status) {
					console.log(res, status)
					if (status === 'success') {
						if (res.code === 0) {
							that.tempList = res.seckill_fee_temp.data
						}
					}
				})
			}
			// 选择商品
			window.choosedata = function() {
				layer.open({
					type: 2,
					title: '选择',
					shadeClose: false,
					shade: 0.5,
					maxmin: true, //开启最大化最小化按钮
					area: ['80%', '80%'],
					content: 'list.html',
					end: function() {},
					success: function() {}
				});
			}
			window.getdata = function(data, name, id) {
				app.productList = [...app.productList, ...data]
				console.log(app.productList, 'app.product.list')
			}
			// 选择活动模板
			window.chooseActive = function() {
				layer.open({
					type: 2,
					title: '选择',
					shadeClose: false,
					shade: 0.5,
					maxmin: true, //开启最大化最小化按钮
					area: ['90%', '90%'],
					content: 'choose_active_temp.html',
					end: function() {
						// console.log(app.type, 'app.type----')
						// seckill_type_show_shop("option", String(app.type))
					},
					success: function(layer, index) {}
				});
			}
			// 选择频道编号
			window.chooseLimit = function() {
				layer.open({
					type: 2,
					title: '选择',
					shadeClose: false,
					shade: 0.5,
					maxmin: true, //开启最大化最小化按钮
					area: ['90%', '90%'],
					content: 'choose_channel.html',
					end: function() {},
					success: function(layer, index) {}
				})
			}
			window.choose = function(data) {
				layer.open({
					type: 2,
					title: '上传图片',
					shadeClose: false,
					shade: 0.5,
					maxmin: true, //开启最大化最小化按钮
					area: ['700px', '400px'],
					content: 'up_report.html?type=' + data,
					end: function() {},
					success: function() {}
				});
			}
			window.getimg = function(data, type) {
				console.log(data);
				if (data) {
					switch (type) {
						case '1':
							createli(data, 'icon_url', type)
							break;
						case '2':
							createli(data, 'img_url', type)
							break;
						default:
							break;
					}
				}
			}

			function createli(data, dom, type) {
				// console.log(data);
				var lihtml = '';
				switch (type) {
					case '1':
						if (data.indexOf(',') == -1) {
							img_arr1.push(data)
						} else {
							for (var i = 0; i < data.split(',').length; i++) {
								img_arr1.push(data.split(',')[i])
							}
						}
						for (var i = 0; i < img_arr1.length; i++) {
							lihtml += '<li class="show_img_li">' +
								'<img src=' + img_arr1[i] + ' >' +
								'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
								'</li>'
						}
						break;
					case '2':
						if (data.indexOf(',') == -1) {
							img_arr2.push(data)
						} else {
							for (var i = 0; i < data.split(',').length; i++) {
								img_arr2.push(data.split(',')[i])
							}
						}
						for (var i = 0; i < img_arr2.length; i++) {
							lihtml += '<li class="show_img_li">' +
								'<img src=' + img_arr2[i] + ' >' +
								'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
								'</li>'
						}
						break;
					default:
						break;
				}
				$('#' + dom).html(lihtml);
			}
			window.delimg = function(i, type, _self) {
				var _type = String(type)
				layer.confirm('确定要删除图片？', function(index) {
					switch (_type) {
						case '1':
							img_arr1.splice(i, 1)
							break;
						case '2':
							img_arr2.splice(i, 1)
							break;
						default:
							break;
					}
					$(_self).parent().remove();
					layer.close(index)
				}, function() {
					layer.msg('取消操作');
				});
			}
		})
	</script>
</html>
